// pages/authorization/authorization.js
var app = getApp();
var jielong = app.data.jielong;
Page({
  /**
   * 页面的初始数据
   */
  data: {},
  onLoad: function (options) {
    var that = this;
    console.log(options)
    wx.request({
      url: jielong + 'action=getSet',
      data: {
        uniacid: app.data.GZHid,
      },
      method: "POST",
      success: function (res) {
        console.log(res)
        if (res.data.msg.imgurl) {
          that.setData({
            img: res.data.msg.imgurl
          })
        }
        if (res.data.data.pick_status == "2") {
          that.setData({
            background: '#64b008',
            backgroundImg: 'https://www.lexiangpingou.cn/addons/lexiangpingou/app/resource/images/xcxjl/bggreen.png'
          })
          wx.setNavigationBarColor({
            backgroundColor: '#64b008',
            frontColor: '#ffffff',
          })
        } else {
          that.setData({
            background: '#dc6992',
            backgroundImg: 'https://www.lexiangpingou.cn/addons/lexiangpingou/app/resource/images/xcxjl/bgred.png'
          })
          wx.setNavigationBarColor({
            backgroundColor: '#dc6992',
            frontColor: '#ffffff',
          })
        }
      }
    })
  },
  onReady: function () {

  },


  onShow: function () {

  },
  bindGetUserInfo: function (e) {
    if (!e.detail.userInfo) {
      return;
    }
    wx.setStorage({
      key: 'userInfo',
      data: e.detail.userInfo,
    })
    this.login()
  },
  login: function () {
    var that = this;
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo, '用户信息')
              wx.setStorage({
                key: 'getuserInfo',
                data: res.userInfo,
              })
              //用户已经授权过
              wx.redirectTo({
                url: '../welcome/welcome',
              })
            }
          })
        } else {
          that.setData({
            Userinfo: true
          })
        }
        // console.log(res.authSetting['scope.userInfo'],1236664)
      }
    })
    wx.getUserInfo({
      success: function (res) {
        console.log(res, 1987666)
        app.data.userInfo = res.userInfo;
        typeof cb == "function" && cb(app.data.userInfo);
        wx.request({
          url: app.data.baseURL + 'op=check_member',
          data: {
            appid: app.data.appid,
            encryptedData: res.encryptedData,
            iv: res.iv,
            session_key: app.data.session_key,
            openid: wx.getStorageSync('openid'),
            nickname: res.userInfo.nickName,
            avatar: res.userInfo.avatarUrl,
            gender: res.userInfo.gender,
            province: res.userInfo.province,
            city: res.userInfo.city,
            gender: res.userInfo.gender,
            mid: app.data.mid ? app.data.mid : '',
            xcx: 1
          },
          success: function (res) {
            // console.log(res.data);
            var data = res.data.member;
            if (data.addmobile && data.addname) {
              wx.setStorage({
                key: "add",
                data: {
                  addmobile: data.addmobile,
                  addname: data.addname
                }
              })
            }
          }
        })
      }
    })
  }
})